package com.atguigu.ai.chat.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class ChatRoleController {
    @Autowired
    private ChatClient chatClient;


    @GetMapping("/chatai")
    public String chatai(@RequestParam(value = "msg",defaultValue = "你是谁") String message) {
        return this.chatClient.prompt().user(message).call().content();
    }

    @GetMapping(value = "/chatai/stream",produces = MediaType.TEXT_PLAIN_VALUE + ";charset=UTF-8")
    public Flux<String> chataiStream(@RequestParam(value = "msg",defaultValue = "你是谁") String message) {
        return this.chatClient.prompt().user(message).stream().content();
    }
}
